package cn.zymall.dict.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.SysDict;
import cn.zymall.common.utils.id.IDUtil;
import cn.zymall.dict.service.DictService;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: DictController
 * @Description: TODO
 * @author: 欧泽昌
 * @date: 2020/8/21 10:19
 * @version: V1.0
 */
@RestController
@RequestMapping("dict")
public class DictController extends BaseController<DictService,SysDict> {
	@Autowired
	DictService dictService;

	@Override
	public boolean insert(@RequestBody SysDict bean) {
		bean.setId(IDUtil.generate8BitUUID());
		bean.setDelFlag(1);
		return super.insert(bean);
	}

	@PostMapping("batchUpdate")
	public int batchUpdate(@RequestBody Map map){
		System.out.println(map);
		List<SysDict> list=null;
		for (Object obj:map.values()) {
			list = JSONObject.parseArray(obj.toString(), SysDict.class);
		}
		return dictService.batchUpdate(list);
	}

	@GetMapping("queryName")
	public List<SysDict> queryName(String name){
		return this.dictService.queryName(name);
	}

}
